'''
Created on 2012-4-1下午3:12:25

@author: nagat
@email:  yasenagat@gmail.com
'''

#读取一个图片，二进制方式打开
f = open('bear.jpg', 'rb')
a = f.read()
f.close()

#a是一个bytes
a = bytes('abcde','utf-8')+a
print(isinstance(a, bytes))
#看看abcde历历在目啊
#abcdeb'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00H\x00H\x00

#二进制度方式打开一个文件,保存加密后的文件
f = open(file='bear_code.jpg',mode='wb')
f.write(a)
f.close()
#
#


##打开加密后的文件
f = open(file='bear_code.jpg',mode='rb')
b = f.read()
f.close()
print(a==b)
#
#
##对a进行解密
#b = b.decode('utf-8')
#b = bytes(b,'utf-8')
print(isinstance(b, str))
b = str(b)
print(isinstance(b, bytes))
#print(b)
print('a :  ',a[0:50])
print('b :  ',b[0:50])
print(b.replace('abcde','')[0:10])
print(bytes(b.replace('abcde',''),'utf-8')[0:10])

#print(a==b)
#
#f = open(file='bear_new.jpg',mode='wb')
#f.write(b)
#f.close()

us = '中国'
bs = b'AAA'
bs2 = bytes('中国','gbk')

#print (us + ':' + str(type(us))) #中国:<class 'str'>
#print (bs) #b'AAA'
#print (bs2) # b'\xd6\xd0\xb9\xfa'
#print (':' + str(type(bs2))) #:<class 'bytes'>
#print (isinstance(bs2.decode('gbk'),str)) #中国
#c = 'abcde'+str(bs2)
#print(c)
#print(bytes(c,'utf-8'))
#print(bytes(c,'utf-8'))



